package fileIO;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class ReadFileThread extends Thread {

	public ReadFileThread(String name) {
		super(name);
	}

	@Override
	public void run() {
		try {
			readLine(20);
			System.out.println(getName());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void readLine(int num) throws IOException {
		String path = "D:\\SQLiteData\\parts\\MES_LT_TP_ALL.sql";
		File file = new File(path);
		try {
			InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8");
			BufferedReader bf = new BufferedReader(isr);
			int lineNum = 0;
			while (bf.readLine() != null && lineNum < num) {
				String lineTxt = bf.readLine();
				System.out.println(lineTxt);
				lineNum++;
			}
			bf.close();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		String path = "D:\\SQLiteData\\parts\\MES_LT_TP_ALL.sql";
		long startTime = System.currentTimeMillis();
		ReadFileThread fileThread1 = new ReadFileThread("thread1");
		ReadFileThread fileThread2 = new ReadFileThread("thread2");
		ReadFileThread fileThread3 = new ReadFileThread("thread3");
		fileThread1.start();
		fileThread2.start();
		fileThread3.start();
		long endTime = System.currentTimeMillis();
		long spendTime = endTime - startTime;
		System.out.println(spendTime);
		long len = new File(path).length();
		System.out.println(len);
		System.out.println("end");
	}
}
